package com.example.demo.controller;

import com.example.demo.entity.MqttData;
import com.example.demo.entity.MqttPublishData;
import com.example.demo.entity.ResponseInfo;
import com.example.demo.service.MqttService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/mqtt")
@Api(tags = "mqtt模拟发送且接收")
public class MqttController {

    @Resource
    MqttService mqttService;

    @PostMapping("/mqttConnect")
    @ApiOperation(value = "mqtt连接模拟接口")
    @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int")
    public ResponseInfo<String> mqttConnect(@RequestParam int id) {
        mqttService.connect(id);
        return ResponseInfo.successInfo("");
    }

    @PostMapping("/addMqttData")
    @ApiOperation(value = "mqttData新增接口")
    public ResponseInfo<String> addMqttData(@RequestBody MqttData mqttData) {
        mqttService.addMqttData(mqttData);
        return ResponseInfo.successInfo("");
    }

    @PostMapping("/addMqttPublishData")
    @ApiOperation(value = "mqttPublishData新增接口")
    public ResponseInfo<String> addMqttPublishData(@RequestBody MqttPublishData mqttPublishData) {
        mqttService.addMqttPublishData(mqttPublishData);
        return ResponseInfo.successInfo("");
    }


    @PostMapping("/mqttPublish")
    @ApiOperation(value = "mqtt模拟消息推送接口")
    @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int")
    public ResponseInfo<String> mqttPublish(@RequestParam int id) {
        return ResponseInfo.successInfo(mqttService.publish(id));
    }
}
